--LoadingUI.lua
require 'fairygui.Window'

LoadingUI = class(Window)
local prop = property(LoadingUI)
prop:accessor("progress", nil)
prop:accessor("title", nil)
prop:accessor("control")

function LoadingUI:__init()
    self:loadLayout("LoadingUI", "Main")
end

function LoadingUI:initEvent()
    self.progress = self:getChild("progress")
    self.control = self:getController("progress")
end

function LoadingUI:initComponent()
end

function LoadingUI:show()
    self:open()
end

function LoadingUI:hide()
    self.control:SetSelectedPage("hide")
    self.progress.text = ""
    self:close()
end

function LoadingUI:onProgress(max, val)
    self.control:SetSelectedPage("show")
    self.progress.text = math.floor((val / max) * 100) .. "%"
end

function LoadingUI:onClose()
end